<template>
  <!-- 添加或修改签收单对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="${comment}" prop="name">
                <el-input v-model="form.name" placeholder="请输入${comment}"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="销售单号" prop="code">
                <el-input v-model="form.code" placeholder="请输入销售单号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户id" prop="customerId">
                <el-input v-model="form.customerId" placeholder="请输入客户id"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户名称" prop="customerName">
                <el-input v-model="form.customerName" placeholder="请输入客户名称"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户地址" prop="customerAddr">
                <el-input v-model="form.customerAddr" placeholder="请输入客户地址"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户电话" prop="customerTel">
                <el-input v-model="form.customerTel" placeholder="请输入客户电话"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="销售记录" prop="saleId">
                <el-input v-model="form.saleId" type="textarea" placeholder="请输入内容"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="送货地址" prop="address">
                <el-input v-model="form.address" placeholder="请输入送货地址"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="销售日期" prop="saleDate">
                <el-date-picker clearable
                                v-model="form.saleDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择销售日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="金额" prop="totalPrice">
                <el-input v-model="form.totalPrice" placeholder="请输入金额"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="金额大写" prop="totalPriceCn">
                <el-input v-model="form.totalPriceCn" placeholder="请输入金额大写"/>
              </el-form-item>
            </el-col>
            <!--<el-col :span="12"><el-form-item label="删除标志" prop="delFlag">
              <el-input v-model="form.delFlag" placeholder="请输入删除标志"/>
            </el-form-item>
                  </el-col>
            <el-col :span="12"><el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注"/>
            </el-form-item>
                  </el-col>-->
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
    import {addAction, getById, updateAction} from '@/api/manage'

    export default {
        name: "GoodsReceiptForm",
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {},
                url: {
                    getById: '/goodsReceipt/goodsReceipt/',
                    add: '/goodsReceipt/goodsReceipt/add',
                    edit: '/goodsReceipt/goodsReceipt/edit',
                },
            };
        },
        created() {

        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                    id: null,
                    name: null,
                    code: null,
                    customerId: null,
                    customerName: null,
                    customerAddr: null,
                    customerTel: null,
                    saleId: null,
                    address: null,
                    saleDate: null,
                    totalPrice: null,
                    totalPriceCn: null,
                    delFlag: null,
                    createBy: null,
                    createTime: null,
                    updateBy: null,
                    updateTime: null,
                    remark: null
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加签收单";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改签收单";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.edit, this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
